P R O C E D U R E   A d d N o d e T o B i n a r y T r e e ( N e w N a m e ,   N e w S c o r e ) 
 
 
 
 	 I F   R o o t   =   0 
 
 	 	 T H E N 
 
 	 	 	 R o o t   !  N e x t F r e e P o s i t i o n 
 
 	 	 E L S E 
 
 	 	 	 / / t r a v e r s e   t h e   t r e e   t o   f i n d   t h e   p o s i t i o n   f o r   t h e   n e w   v a l u e 
 
 	 	 	 C u r r e n t P o s i t i o n   !  R o o t 
 
 	 	 	 L a s t M o v e   !   X  
 
 	 	 	 R E P E A T 
 
 	 	 	 	 P r e v i o u s P o s i t i o n   !  C u r r e n t P o s i t i o n 
 
 	 	 	 	 I F   N e w S c o r e   <   T h i s T r e e [ C u r r e n t P o s i t i o n ] . S c o r e 
 
 	 	 	 	 	 T H E N 
 
 	 	 	 	 	 	 / / m o v e   l e f t 
 
 	 	 	 	 	 	 L a s t M o v e   !   L  
 
 	 	 	 	 	 	 C u r r e n t P o s i t i o n   !  T h i s T r e e [ C u r r e n t P o s i t i o n ] . L e f t P 
 
 	 	 	 	 	 E L S E 
 
 	 	 	 	 	 	 / /   m o v e   r i g h t 
 
 	 	 	 	 	 	 L a s t M o v e   !   R  
 
 	 	 	 	 	 	 C u r r e n t P o s i t i o n   !  T h i s T r e e [ C u r r e n t P o s i t i o n ] . R i g h t P 
 
 	 	 	 	 E N D I F 
 
 	 	 	 U N T I L   C u r r e n t P o s i t i o n   =   0 
 
 	 E N D I F 
 
 
 
 	 I F   L a s t M o v e   =    R  
 
 	 	 T H E N 
 
 	 	 	 T h i s T r e e [ P r e v i o u s P o s i t i o n ] . R i g h t P   !  N e x t F r e e P o s i t i o n 
 
 	 	 E L S E 
 
 	 	 	 T h i s T r e e [ P r e v i o u s P o s i t i o n ] . L e f t P   !  N e x t F r e e P o s i t i o n 
 
 	 E N D I F 
 
 	 N e x t F r e e P o s i t i o n   !  T h i s T r e e [ N e x t F r e e P o s i t i o n ] . L e f t P   
 
 E N D P R O C E D U R E 